package programer.interviewer;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Question8 {
    //[[1,2,3],            //[[7,4,1],
    // [4,5,6],   ==>      // [8,5,2],
    // [7,8,9]]            // [9,6,3]]
    public void setZeroes(int[][] matrix) {
        Set<Integer> rowSet = new HashSet<Integer>();
        Set<Integer> colSet = new HashSet<Integer>();
        int row = matrix.length;
        int col = matrix[0].length;

        //[0,0]=>[0,2]    [1,0]=>[0,1]  [2,0] => [0,0]
        //[0,1]=>[1,2]    [1,1]=>[1,1]  [2,1] => [1,0]
        //[0,2]=>[2,2]    [1,2]=>[2,1]  [2,2] => [2,0]
        System.out.println("row:" + row);
        for(int i = 0; i < row; i++) {
            for(int j= 0;j< col;j++) {
                if(matrix[i][j] == 0) {
                    rowSet.add(i);
                    colSet.add(j);
                }
            }
        }
        Arrays.asList(matrix).forEach((it -> System.out.println(Arrays.toString(it))));

       rowSet.forEach(it -> {
           for (int i = 0;i< col; i++) {
               matrix[it][i] = 0;
           }
       });

       colSet.forEach(it -> {
            for (int i = 0;i< row;i++) {
                matrix[i][it] = 0;
            }
       });

        System.out.println("result:");
        Arrays.asList(matrix).forEach((it -> System.out.println(Arrays.toString(it))));
    }

    public static void main(String[] args) {
        new Question8().setZeroes(new int[][]{{0,0,3,5}, {5,6,7,8} , {8,9,10,11}, {12,13,14,15}});
    }
}
